// @ts-ignore
import {message} from "ant-design-vue";
/**
 * url是否为外部链接
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path: string) {
    return /^(https?:|http?:|mailto:|tel:)/.test(path)
}

export function isEmpty(obj: any) {
    return obj===undefined || obj==null || obj===''
}

export function copyText(text:string,successMsg?:string){
    navigator.clipboard.writeText(text).then(() => {
        if(successMsg){
            message.success(successMsg);
        }
    }).catch(error => {
        //如果用户没有授权，会抛出错误
        message.error('复制失败：' + error);
    });
}

/**
 * js产生随机数函数
 * @param n 随机数位数
 */
export function randomNum(n:number) {
    let rnd = "";
    for (var i = 0; i < n; i++)
        rnd += Math.floor(Math.random() * 10);
    return rnd;
}

